<template>
<div :class="[$style.container]">
<el-checkbox v-model="checked">开机自动启动</el-checkbox>
</div>
</template>

<script lang="ts">

import { Vue, Component, Prop, Emit, Ref } from 'vue-property-decorator'
import { remote } from 'electron'

const mac = process.platform === 'darwin'

@Component
export default class LaunchSetting extends Vue {
  localChecked = mac ? remote.app.getLoginItemSettings()?.openAtLogin : !!remote.app.getLoginItemSettings()?.executableWillLaunchAtLogin

  get checked () {
    return this.localChecked
  }

  set checked (value: boolean) {
    remote.app.setLoginItemSettings({
      openAtLogin: !!value,
      path: process.execPath,
      openAsHidden: true,
      args: ['--autostart']
    })
    this.localChecked = mac ? remote.app.getLoginItemSettings()?.openAtLogin : !!remote.app.getLoginItemSettings()?.executableWillLaunchAtLogin
  }
}
</script>

<style lang="scss" module>
@import "~@/styles/vars.scss";

.container {
  display: flex;
  justify-content: center;
}
</style>
